/**Variable**/
@import './helpers/mixin.scss';

$btnThemeList: (
  (
    name: "primary",
    textColor: var(--vxe-primary-color),
    btnColor: #fff,
    btnLightenColor: var(--vxe-primary-lighten-color),
    btnDarkenColor: var(--vxe-primary-darken-color),
    btnDisabledColor: var(--vxe-primary-disabled-color)
  ),
  (
    name: "success",
    textColor: var(--vxe-success-color),
    btnColor: #fff,
    btnLightenColor: var(--vxe-success-lighten-color),
    btnDarkenColor: var(--vxe-success-darken-color),
    btnDisabledColor: var(--vxe-success-disabled-color)
  ),
  (
    name: "info",
    textColor: var(--vxe-info-color),
    btnColor: #fff,
    btnLightenColor: var(--vxe-info-lighten-color),
    btnDarkenColor: var(--vxe-info-darken-color),
    btnDisabledColor: var(--vxe-info-disabled-color)
  ),
  (
    name: "warning",
    textColor: var(--vxe-warning-color),
    btnColor: #fff,
    btnLightenColor: var(--vxe-warning-lighten-color),
    btnDarkenColor: var(--vxe-warning-darken-color),
    btnDisabledColor: var(--vxe-warning-disabled-color)
  ),
  (
    name: "danger",
    textColor: var(--vxe-danger-color),
    btnColor: #fff,
    btnLightenColor: var(--vxe-danger-lighten-color),
    btnDarkenColor: var(--vxe-danger-darken-color),
    btnDisabledColor: var(--vxe-danger-disabled-color)
  ),
  (
    name: "perfect",
    textColor: var(--vxe-table-header-background-color),
    btnColor: var(--vxe-font-color),
    btnLightenColor: var(--vxe-table-header-background-color),
    btnDarkenColor: var(--vxe-table-header-background-color),
    btnDisabledColor: var(--vxe-table-header-background-color)
  )
);

.vxe-button {
  position: relative;
  text-align: center;
  background-color: var(--vxe-button-default-background-color);
  outline: 0;
  font-size: var(--vxe-font-size);
  max-width: var(--vxe-button-max-width);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  white-space: nowrap;
  user-select: none;
  appearance: none;
  @include animatTransition(border, .2s);
  &:not(.is--disabled) {
    color: var(--vxe-font-color);
    cursor: pointer;
  }
  &.is--loading {
    cursor: progress;
    &:before {
      content: "";
      position: absolute;
      left: -1px;
      top: -1px;
      right: -1px;
      bottom: -1px;
      border-radius: inherit;
      background-color: hsla(0,0%,100%,.35);
      pointer-events: none;
    }
  }
  &.is--disabled {
    color: var(--vxe-font-disabled-color);
    &:not(.is--loading) {
      cursor: no-drop;
    }
  }
  &.type--text {
    text-decoration: none;
    border: 0;
    padding: 0.1em 0.5em;
    background-color: transparent;
    &:not(.is--disabled) {
      &:focus {
        color: var(--vxe-font-darken-color);
      }
      &:hover {
        color: var(--vxe-primary-lighten-color);
      }
    }
    @for $index from 0 to length($btnThemeList) {
      $item: nth($btnThemeList, $index + 1);
      &.theme--#{map-get($item, name)} {
        color: map-get($item, textColor);
        &:not(.is--disabled) {
          &:focus {
            color: map-get($item, btnDarkenColor);
          }
          &:hover {
            color: map-get($item, btnLightenColor);
          }
        }
        &.is--disabled {
          color: map-get($item, btnDisabledColor);
        }
      }
    }
  }
  &.type--button {
    font-family: inherit;
    height: var(--vxe-button-height-default);
    line-height: 1;
    border: 1px solid var(--vxe-input-border-color);
    &.is--round {
      border-radius: var(--vxe-button-round-border-radius-default);
    }
    &:not(.is--round) {
      border-radius: var(--vxe-border-radius);
    }
    &.is--circle {
      padding: 0 0.5em;
      min-width: var(--vxe-button-height-default);
      border-radius: 50%;
    }
    &:not(.is--circle) {
      padding: 0 1em;
    }
    &:not(.is--disabled) {
      &:hover {
        color: var(--vxe-primary-lighten-color);
      }
      &:focus {
        border-color: var(--vxe-primary-color);
      }
      &:active {
        color: var(--vxe-primary-darken-color);
        border-color: var(--vxe-primary-darken-color);
        background-color: var(--vxe-button-default-background-color);
      }
    }
    @for $index from 0 to length($btnThemeList) {
      $item: nth($btnThemeList, $index + 1);
      $textColor: map-get($item, textColor);
      $btnColor: map-get($item, btnColor);
      &.theme--#{map-get($item, name)} {
        color: $btnColor;
        &:not(.is--disabled) {
          border-color: $textColor;
          background-color: $textColor;
          &:hover {
            color: $btnColor;
            background-color: map-get($item, btnLightenColor);
            border-color: map-get($item, btnLightenColor);
          }
          &:active {
            color: $btnColor;
            background-color: map-get($item, btnDarkenColor);
            border-color: map-get($item, btnDarkenColor);
          }
        }
        &.is--disabled {
          border-color: map-get($item, btnDisabledColor);
          background-color: map-get($item, btnDisabledColor);
        }
        &.is--loading {
          border-color: $textColor;
          background-color: $textColor;
        }
      }
    }
  }
  &.size--medium {
    font-size: var(--vxe-font-size-medium);
    &.type--button {
      height: var(--vxe-button-height-medium);
      &.is--circle {
        min-width: var(--vxe-button-height-medium);
      }
      &.is--round {
        border-radius: var(--vxe-button-round-border-radius-medium);
      }
    }
    .vxe-button--loading-icon,
    .vxe-button--icon {
      min-width: var(--vxe-font-size-medium);
    }
  }
  &.size--small {
    font-size: var(--vxe-font-size-small);
    &.type--button {
      height: var(--vxe-button-height-small);
      &.is--circle {
        min-width: var(--vxe-button-height-small);
      }
      &.is--round {
        border-radius: var(--vxe-button-round-border-radius-small);
      }
    }
    .vxe-button--loading-icon,
    .vxe-button--icon {
      min-width: var(--vxe-font-size-small);
    }
  }
  &.size--mini {
    font-size: var(--vxe-font-size-mini);
    &.type--button {
      height: var(--vxe-button-height-mini);
      &.is--circle {
        min-width: var(--vxe-button-height-mini);
      }
      &.is--round {
        border-radius: var(--vxe-button-round-border-radius-mini);
      }
    }
    .vxe-button--loading-icon,
    .vxe-button--icon {
      min-width: var(--vxe-font-size-mini);
    }
  }
}
.vxe-input,
.vxe-button {
  &+.vxe-button.type--button,
  &+.vxe-button--dropdown {
    margin-left: 12px;
  }
}
.vxe-button--loading-icon,
.vxe-button--icon {
  min-width: var(--vxe-font-size);
  &+.vxe-button--content {
    margin-left: 4px;
  }
}
.vxe-button--wrapper,
.vxe-button--dropdown {
  display: inline-block;
}
.vxe-button--dropdown {
  position: relative;
  &+.vxe-button.type--button,
  &+.vxe-button--dropdown {
    margin-left: 12px;
  }
  & > .vxe-button {
    &.type--button {
      @for $index from 0 to length($btnThemeList) {
        $item: nth($btnThemeList, $index + 1);
        $btnColor: map-get($item, btnColor);
        &.theme--#{map-get($item, name)} {
          color: $btnColor;
        }
      }
    }
  }
  &.is--active {
    & > .vxe-button {
      &:not(.is--disabled) {
        color: var(--vxe-primary-lighten-color);
      }
      &.type--text {
        @for $index from 0 to length($btnThemeList) {
          $item: nth($btnThemeList, $index + 1);
          &.theme--#{map-get($item, name)} {
            color: map-get($item, btnLightenColor);
          }
        }
      }
      &.type--button {
        @for $index from 0 to length($btnThemeList) {
          $item: nth($btnThemeList, $index + 1);
          &.theme--#{map-get($item, name)} {
            color: map-get($item, btnColor);
            background-color: map-get($item, btnLightenColor);
            border-color: map-get($item, btnLightenColor);
          }
        }
      }
    }
    .vxe-button--dropdown-arrow {
      transform: rotate(180deg);
    }
  }
}

.vxe-button--dropdown-arrow {
  display: inline-block;
  font-size: 12px;
  margin-left: 4px;
  @include animatTransition(transform, .2s);
}

.vxe-button--dropdown-panel {
  display: none;
  position: absolute;
  right: 0;
  padding: 4px 0;
  &.animat--leave {
    display: block;
    opacity: 0;
    transform: scaleY(0.5);
    transition: transform .3s cubic-bezier(.23,1,.32,1), opacity .3s cubic-bezier(.23,1,.32,1);
    transform-origin: center top;
    backface-visibility: hidden;
    transform-style: preserve-3d;
    &[placement="top"] {
      transform-origin: center bottom;
    }
  }
  &.animat--enter {
    opacity: 1;
    transform: scaleY(1);
  }
}
.vxe-button--dropdown-wrapper {
  padding: 5px;
  background-color: var(--vxe-button-dropdown-panel-background-color);
  border-radius: var(--vxe-border-radius);
  border: 1px solid var(--vxe-input-border-color);
  box-shadow: 0 1px 6px rgba(0,0,0,.2);
  & > .vxe-button.type--text,
  & > .vxe-button.type--button {
    display: block;
    width: 100%;
    border: 0;
    margin: 0.4em 0 0 0;
  }
  & > .vxe-button {
    &.type--text {
      padding: 2px 8px;
    }
    &:first-child {
      margin-top: 0;
    }
    &:last-child {
      margin-bottom: 0;
    }
  }
}